package wiki.kaizen.cloud.shiro.stateless.config;

import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.Map;

/**
 * 默认的 异常 响应控制器
 * @author  xeepoo
 * */
@RequestMapping("/kaizen")
@RestController
public class DefaultControllerConfig {

    @GetMapping("/login")
    public Map<String,Object> login(String msg){
        return new HashMap<String,Object>(2){
            {
                put("code", HttpServletResponse.SC_UNAUTHORIZED);
                put("msg",StringUtils.isEmpty(msg)?"需要登录":msg);
            }
        };
    }

    @GetMapping("/unauthorized")
    public Map<String,Object> unauthorized(){
        return new HashMap<String,Object>(2){
            {
                put("code", HttpServletResponse.SC_FORBIDDEN);
                put("msg","权限不足");
            }
        };
    }
    @GetMapping("/kickout")
    public Map<String,Object> kickout() {
        return new HashMap<String, Object>(2) {
            {
                put("code", HttpServletResponse.SC_FORBIDDEN);
                put("msg", "您已被强制下线,该账号已在其他地方登陆.");
            }
        };
    }

    @GetMapping("/locked")
    public Map<String,Object> locked(){
        return new HashMap<String, Object>(2) {
            {
                put("code", HttpServletResponse.SC_FORBIDDEN);
                put("msg", "您的账号已被锁定.");
            }
        };
    }
}
